package Demo1;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class RequestTest extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();
        Map<String,String[]> stringMap = req.getParameterMap();
        Set<String> keys = stringMap.keySet();
        Iterator<String> it = keys.iterator();
        while(it.hasNext()){
            String name = it.next();
            out.println(name);
            // 这里得到的是value集合中的第一个元素
            String value = req.getParameter(name);
            out.println();
            out.println(value);
        }

        String[] usernames = req.getParameterValues("username");
        String[] userpwds = req.getParameterValues("userpwd");
        String[] hobbys = req.getParameterValues("hobby");
        for(String name:usernames){
            out.println(name);
        }
        for (String userpwd:userpwds){
            out.println(userpwd);
        }

        for (String hobby:hobbys){
            out.println(hobby);
        }

    }
}
